package com.mall.huohuo.exception.handler;

import com.mall.huohuo.exception.BusinessException;
import com.mall.huohuo.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Configuration
@RestControllerAdvice
@Slf4j(topic = "GlobalExceptionHandler")
public class GlobalExceptionHandler {

    @ExceptionHandler(BusinessException.class)
    public Result handleBusinessException(BusinessException businessException){
        log.error("error-message:{}",businessException.getMessage(),businessException);
//        log.error(businessException);
//        log.info()
        return Result.exception(businessException.getMessage(),businessException.getCode());
    }
}
